using HKB.Common;
using HKB.Data.Dal;
using HKB.Data.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace HKB.Data.Bll
{
	public class UserGiftCardFaceValueBll
	{
		private static UserGiftCardFaceValueBll _instance = null;
		private readonly UserGiftCardFaceValueDal dal = new UserGiftCardFaceValueDal();
		public static UserGiftCardFaceValueBll instance
		{
			get
			{
				if (UserGiftCardFaceValueBll._instance == null)
				{
					UserGiftCardFaceValueBll._instance = new UserGiftCardFaceValueBll();
				}
				return UserGiftCardFaceValueBll._instance;
			}
		}
		public bool Exists(long id)
		{
			return this.dal.Exists(id);
		}
		public long Add(UserGiftCardFaceValueModel model)
		{
			return this.dal.Add(model);
		}
		public bool Update(UserGiftCardFaceValueModel model)
		{
			return this.dal.Update(model);
		}
		public bool Delete(long id)
		{
			return this.dal.Delete(id);
		}
		public bool DeleteList(string idlist)
		{
			return this.dal.DeleteList(idlist);
		}
		public UserGiftCardFaceValueModel GetModel(long id)
		{
			return this.dal.GetModel(id);
		}
		public UserGiftCardFaceValueModel GetModelByCache(long id)
		{
			string cacheKey = "UserGiftCardFaceValueModel_" + id;
			object obj = DataCache.GetCache(cacheKey);
			if (obj == null)
			{
				try
				{
					obj = this.dal.GetModel(id);
					if (obj != null)
					{
						int configInt = ConfigHelper.GetConfigInt("ModelCache");
						DataCache.SetCache(cacheKey, obj, System.DateTime.Now.AddMinutes((double)configInt), System.TimeSpan.Zero);
					}
				}
				catch
				{
				}
			}
			return (UserGiftCardFaceValueModel)obj;
		}
		public DataSet GetList(string strWhere)
		{
			return this.dal.GetList(strWhere);
		}
		public DataSet GetList(int Top, string strWhere, string filedOrder)
		{
			return this.dal.GetList(Top, strWhere, filedOrder);
		}
		public System.Collections.Generic.List<UserGiftCardFaceValueModel> GetModelList(string strWhere)
		{
			DataSet list = this.dal.GetList(strWhere);
			return this.DataTableToList(list.Tables[0]);
		}
		public System.Collections.Generic.List<UserGiftCardFaceValueModel> DataTableToList(DataTable dt)
		{
			System.Collections.Generic.List<UserGiftCardFaceValueModel> list = new System.Collections.Generic.List<UserGiftCardFaceValueModel>();
			int count = dt.Rows.Count;
			if (count > 0)
			{
				for (int i = 0; i < count; i++)
				{
					UserGiftCardFaceValueModel userGiftCardFaceValueModel = new UserGiftCardFaceValueModel();
					if (dt.Rows[i]["id"] != null && dt.Rows[i]["id"].ToString() != "")
					{
						userGiftCardFaceValueModel.id = new long?(long.Parse(dt.Rows[i]["id"].ToString()));
					}
					userGiftCardFaceValueModel.FestivalName = dt.Rows[i]["FestivalName"].ToString();
					if (dt.Rows[i]["FaceValue"] != null && dt.Rows[i]["FaceValue"].ToString() != "")
					{
						userGiftCardFaceValueModel.FaceValue = new decimal?(decimal.Parse(dt.Rows[i]["FaceValue"].ToString()));
					}
					if (dt.Rows[i]["DiscountRate"] != null && dt.Rows[i]["DiscountRate"].ToString() != "")
					{
						userGiftCardFaceValueModel.DiscountRate = new int?(int.Parse(dt.Rows[i]["DiscountRate"].ToString()));
					}
					list.Add(userGiftCardFaceValueModel);
				}
			}
			return list;
		}
		public DataSet GetAllList()
		{
			return this.GetList("");
		}
		public DataSet GetPagedList(int PageIndex, int PageSize, string strWhere, string Order)
		{
			return this.dal.GetPagedList(PageIndex, PageSize, strWhere, Order);
		}
		public DataSet PageOrderList(int PageSize, int PageIndex, string Orderfld, int OrderType, string strWhere)
		{
			return Conn.ExecProSpPageOrder("MBF_UserGiftCardFaceValue", " ROW_NUMBER() OVER (ORDER BY id asc) rowid,*", PageSize, PageIndex, Orderfld, OrderType, strWhere);
		}
		public DataSet GetList(string columns, string strWhere)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.AppendFormat("select {0} ", columns);
			stringBuilder.Append(" FROM MBF_UserGiftCardFaceValue ");
			if (strWhere.Trim() != "")
			{
				stringBuilder.Append(" where " + strWhere);
			}
			return Conn.Query(stringBuilder.ToString(), new IDbDataParameter[0]);
		}
	}
}
